package omm.domain.evolutiongraph;

import java.util.Map;
import java.util.TreeMap;

import org.joda.time.DateTime;
import org.joda.time.DateTimeComparator;


/*******
 * @deprecated POR REQUERIMIENTOS DEL USUARIO
 * @author jbatllori
 *
 */

public class AnualByYearPeriodStrategy implements PeriodStrategy {

	final private Integer periodsMax;
	
	public AnualByYearPeriodStrategy() {
		periodsMax = 4;
	}
	
	@Override
	public Map<DateTime, Double> calculatePeriods() {
		Map<DateTime, Double> periodsBars = new TreeMap<DateTime, Double>(
				DateTimeComparator.getDateOnlyInstance());
		// Carga de fechas
		DateTime actualTime = new DateTime(System.currentTimeMillis());
		DateTime time = new DateTime(actualTime.getYear(), actualTime.getMonthOfYear(), 1, 0, 0, 0);
		int iterations = periodsMax;
		DateTime itTime = time;
		int year = itTime.getYear();
		for (int i = 0; i < iterations; i++) {
			itTime = new DateTime(year, 1 , 1, 0, 0, 0);
			periodsBars.put(itTime, 0.0);
			year = itTime.getYear() - 1;
		}
		return periodsBars;
	}

	@Override
	public Integer calculateBarsWidth() {
		return (int) (380 / (periodsMax + 1));
	}

	@Override
	public boolean isInPeriod(DateTime modifTime, DateTime dt) {
		return dt.getYear() == modifTime.getYear();
	}

	@Override
	public String calculatePeriodsNames(Map<DateTime, Double> periodsValue) {
		String periodsNames = "";
		for (Map.Entry<DateTime, Double> e : periodsValue.entrySet()) {
			DateTime dt = e.getKey();
			Integer year = dt.getYear();
			periodsNames = periodsNames + year.toString().substring(2) + '|';
			}
		return periodsNames.substring(0, periodsNames.length() - 1);
	}

	@Override
	public Integer calculateBarsSeparation() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getTitle() {
		return "anual";
	}

	@Override
	public DateTime getBegin() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DateTime getEnd() {
		// TODO Auto-generated method stub
		return null;
	}

}
